import apis from "../../../api/apis";
export default {
  namespaced: true,
  state: {
    // 所有房间相关信息
    allRooms: [],
    freeRoom: '',
    userRoom: '',
    clearRoom: '',
    // 开台信息
    founding:{roomNum:'',numberofpeopleserved:''}
  },
  mutations: {
    // 所有房间数据
    allRoom(state, data) {
      state.allRooms = data
      // console.log(data.list);
      // 空闲房间数量
      const arr = data.list.filter(item => item.roomState == 0)
      state.freeRoom = arr.length
      //  console.log(state.freeRoom);
      // 使用中房间数量
      const arr2 = data.list.filter(item => item.roomState == 1)
      state.userRoom = arr2.length
      //  console.log(state.userRoom);
      // 清扫房间数量
      const arr3 = data.list.filter(item => item.roomState == 2)
      state.clearRoom = arr3.length
      //  console.log(state.clearRoom);
    },
    // // 房间开台
    // founding(){

    // }
  },
  actions: {
    // 获取所有房间
    async getRoom(context) {
      const data = await apis.rooms.getAllRoom()
      if (data.data.stateCode == 200) {
        context.commit('allRoom', data.data.data)
      }
    },
      // 房间开台
      async founding(context,val) {
        const data = await apis.rooms.founding(val)
        return data
      },
  }
}